package check.md5;

import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.security.MessageDigest;

public class CheckedSumOutputStream extends FilterOutputStream {
    private MessageDigest mdDigest;

    public CheckedSumOutputStream(OutputStream out, MessageDigest mdDigest) {
        super(out);
        this.mdDigest = mdDigest;        
    }

    public void write(int b) throws IOException {
        out.write(b);
        mdDigest.update((byte) b);	// Pytanie czy zadziala
    }

    public void write(byte[] b, int off, int len) throws IOException {
        out.write(b, off, len);
        mdDigest.update(b, off, len);
    }
    
    public MessageDigest getMessageDigest() {
        return mdDigest;
    }
}
